﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SeaBattle.Domain.Abstract;
using SeaBattle.Domain.Entities;
using SeaBattle.Domain.Abstract.Services;

namespace SeaBattle.Domain.Concrete
{
    public class FakePlayerRepository:IPlayerRepository
    {
        private static List<Player> players = new List<Player>
        {
            new Player("Василий Пупкин","vasya"),
            new Player("Николай Фоменко","kolya"),
            new Player("Александр Бородач","sanya")
        };

        public Player CreateNewPlayer(string name, string login)
        {
            return new Player(name, login);
        }

        public void SavePlayer(Player player)
        {
            if (!players.Contains(player))
            {
                players.Add(player);
            }
        }

        public Player GetPlayer(string login)
        {
            var player = players.FirstOrDefault(x => x.Login == login);
            if (player == null)
            {
                throw new IndexOutOfRangeException("Player with login " + login + " does not exists");
            }
            return player;
        }

        public Player GetPlayer(int id)
        {
            var player = players.FirstOrDefault(x => x.Id == id);
            if (player == null)
            {
                throw new IndexOutOfRangeException("Player with login " + id + " does not exists");
            }
            return player;
        }

        public IEnumerable<Player> GetAllPlayers()
        {
            return players.AsEnumerable();
        }
    }
}